<?php
// Authenticate
require("class.AuthenticationManager.php");
require("class.CommandMenu.php");
if (!$authenticationManager->isLoggedIn() || !$authenticationManager->hasClearance(CLEARANCE_ADMINISTRATOR)) {
    Header("Location: login.php?redirect=$_SERVER[PHP_SELF]&clearanceRequired=Administrator");
    exit;
}

// Connect to database:
$dbh = dbConnect();

// Include table_names
include("table_names.inc");

// Load local vars from superglobals:
if (isset($_REQUEST['day']))
{    
    $day = $_REQUEST['day'];
}
if (isset($_REQUEST['month']))
{    
    $month = $_REQUEST['month'];
}
if (isset($_REQUEST['year']))
{    
    $year = $_REQUEST['year'];
}
if (isset($_REQUEST['mode']))
{    
    $mode = $_REQUEST['mode'];
}
/*
if (isset($_REQUEST['query']))
{    
    $query = $_REQUEST['query'];
}*/
if (isset($_REQUEST['contextUser']))
{    
    $contextUser = $_REQUEST['contextUser'];
}


$startYear   = $year;
$startMonth  = $month;
$startDay    = 1;
$endYear     = $year;
$endMonth    = $month;
$endDay      = date('t',mktime(0,0,0,$month, 1, $year));

		
//build the database query
$myQuery =  "SELECT    date_format(start_time,'%d') AS day_of_month, ".
                      "unix_timestamp(end_time) - unix_timestamp(start_time) AS diff_sec, ".
					  "end_time AS end_time_str, ".
					  "start_time AS start_time_str, ".
					  "unix_timestamp(start_time) AS start_time, ".
					  "unix_timestamp(end_time) AS end_time, ".
					  "$PROJECT_TABLE.title AS projectTitle, " .
					  "$TASK_TABLE.name AS taskName, " .
					  "$TIMES_TABLE.task_id, " .
					  "$CLIENT_TABLE.organisation AS clientName " .
			"FROM      $TIMES_TABLE, $TASK_TABLE, $PROJECT_TABLE, $CLIENT_TABLE ".
			"WHERE     uid='$contextUser' ".
			"AND       $TASK_TABLE.task_id = $TIMES_TABLE.task_id ".
		    "AND       ($TASK_TABLE.source_project = $PROJECT_TABLE.title OR $TASK_TABLE.target_project = $PROJECT_TABLE.title) ".
		    "AND       $PROJECT_TABLE.client_id = $CLIENT_TABLE.client_id ".
		    "AND       ((start_time >= '$startYear-$startMonth-$startDay 00:00:00' ".
		    "AND       start_time < '$endYear-$endMonth-$endDay 00:00:00') OR(end_time >= '$startYear-$startMonth-$startDay 00:00:00' ".
		    "AND       end_time < '$endYear-$endMonth-$endDay 00:00:00') OR (start_time < '$startYear-$startMonth-$startDay 00:00:00' ".
		    "AND       end_time >= '$endYear-$endMonth-$endDay 00:00:00')) ".
		    "ORDER BY  projectTitle, taskName, start_time";







//run the query  
//list($qh,$num) = dbQuery($query);

/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
//date_default_timezone_set('Europe/Paris');

if (PHP_SAPI == 'cli')
	die('This example should only be run from a Web Browser');

/** Include PHPExcel */
require_once 'Classes/PHPExcel.php';


// Create new PHPExcel object
$objPHPExcel = new PHPExcel();



// Insert Silkan Logo:
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('PHPExcel logo');
$objDrawing->setDescription('PHPExcel logo');
$objDrawing->setPath('./images/silkan.gif');
$objDrawing->setHeight(60);
$objDrawing->setCoordinates('E3');
//$objDrawing->setOffsetX(-10);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

// Merge Cells
$objPHPExcel->getActiveSheet()->mergeCells('E3:E5');

// Context (imputation du:):
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B4', 'Imputation du:');			
$objPHPExcel->getActiveSheet()->getStyle('B4')->getFont()->setSize(12);
$objPHPExcel->getActiveSheet()->getStyle('B4')->getFont()->setBold(true);
// Context (au:):
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B5', 'Au:');			
$objPHPExcel->getActiveSheet()->getStyle('B5')->getFont()->setSize(12);
$objPHPExcel->getActiveSheet()->getStyle('B5')->getFont()->setBold(true);



// Context (Company / username / date):
$cQuery           = "SELECT company, username FROM $USER_TABLE WHERE username='$contextUser'";
list($cQh, $cNum) = dbQuery($cQuery);
$cData            = dbResult($cQh);
$curent_company   = utf8_encode(stripslashes($cData['company']));

$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(2, 2, $curent_company);
$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(2, 3, $contextUser);
$objPHPExcel->getActiveSheet()->getStyle('C3')->getFont()->setSize(12);
$objPHPExcel->getActiveSheet()->getStyle('C3')->getFont()->setBold(true);
$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(2, 4, date('d/m/o',mktime(0,0,0,$month, 1, $year)));
$objPHPExcel->getActiveSheet()->getStyle('C4')->getFont()->setSize(12);
$objPHPExcel->getActiveSheet()->getStyle('C4')->getFont()->setBold(true);
$limitDaybymonth = date('t',mktime(0,0,0,$month, 1, $year));
$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(2, 5, date('d/m/o',mktime(0,0,0,$month, $limitDaybymonth, $year)));
$objPHPExcel->getActiveSheet()->getStyle('C5')->getFont()->setSize(12);
$objPHPExcel->getActiveSheet()->getStyle('C5')->getFont()->setBold(true);




/*
// Date:
$todayDate = date('D F j, Y',mktime(0,0,0,$month, 1, $year));
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('B7', $todayDate);			
$objPHPExcel->getActiveSheet()->getStyle('B7')->getFont()->setSize(14);
*/


// Set document properties
$objPHPExcel->getProperties()->setCreator(       "TimeSheet.php")
							 ->setLastModifiedBy("TimeSheet.php")
							 ->setTitle(         "Office 2007 XLSX Test Document")
							 ->setSubject(       "Office 2007 XLSX Test Document")
							 ->setDescription(   "Test document for Office 2007 XLSX, generated using PHP classes.")
							 ->setKeywords(      "office 2007 openxml php")
							 ->setCategory(      "Test result file");



// Table:
$objPHPExcel->setActiveSheetIndex(0)               
            ->setCellValue('B8', 'Projet')
            ->setCellValue('c8', 'Tâche')
            ->setCellValue('d8', 'Cumul mois');		
$d = 1;
while ($d<=date('t',mktime(0,0,0,$month, 1, $year)))
{
    setlocale(LC_TIME, 'fra_fra');
    $objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(3 + $d, 8, strftime('%d',mktime(0,0,0,$month, $d, $year)));
	$d = $d + 1;
}			
			
			
			
list($myQh, $myNum) = dbQuery($myQuery);
if ($myNum >= 1)
{
    $row = 9;
	$last_project_title = "";
	$last_task_name     = "";
	$last_date          = 0;
	$current_cumul      = 0;
	$total              = 0;
    while ($myData = dbResult($myQh))
    {
	    
		$current_project_title = utf8_encode(stripslashes($myData["projectTitle"]));
		$current_task_name     = utf8_encode(stripslashes($myData["taskName"]));
		$current_date          = date('j',$myData["start_time"]) + 1;
	    
		// Project title:
		if ($last_project_title != $current_project_title)
        {		
		    $objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(1, $row, $current_project_title);
            $objPHPExcel->getActiveSheet()->getStyle('B'.$row.'')->getFont()->setBold(true); 
			$last_task_name = "";
			
			if (date('t',mktime(0,0,0,$month, 1, $year)) == 28)
            {
				$cst = 'B'.$row.':AF'.$row.'';
            }
            if (date('t',mktime(0,0,0,$month, 1, $year)) == 29)
            {
                $cst = 'B'.$row.':AG'.$row.'';
            }
            if (date('t',mktime(0,0,0,$month, 1, $year)) == 30)
            {
                $cst = 'B'.$row.':AH'.$row.'';	
            }
            if (date('t',mktime(0,0,0,$month, 1, $year)) == 31)
            {
                $cst = 'B'.$row.':AI'.$row.'';	
            }
			
		    $objPHPExcel->getActiveSheet()->getStyle($cst)->applyFromArray(array(
                'borders'=>array(
                    'top'=>array(
                        'style'=>PHPExcel_Style_Border::BORDER_MEDIUM),
                    'bottom'=>array(
                        'style'=>PHPExcel_Style_Border::BORDER_NONE))));
			
		}
		
		//duration:
		$myData["start_time"] = strtotime($myData["start_time_str"]);
        $myData["end_time"]   = strtotime($myData["end_time_str"]);
		$startTimeStr         = date('G',$myData["start_time"]);
        $endTimeStr           = date('G',$myData["end_time"]);
		$duration             = ($endTimeStr - $startTimeStr) / 8;
		
		
		if ($last_task_name == $current_task_name)
        {
		    $current_cumul = $current_cumul + $duration;
		    $row           = $row - 1;
		} else {
		    $current_cumul = $duration;
		}
		
		// Task name
		$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(2, $row, $current_task_name);
		// Date:
		$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(3 + $current_date, $row, $duration);
		// Cumul:
		$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(3, $row, $current_cumul);
		
		
	    $last_project_title = $current_project_title;
		$last_task_name     = $current_task_name;
		$last_date          = $current_date;
		$total = $total + $duration;
	    $row = $row + 1;
	}
	$row = $row + 1;
	// Total:
    if (date('t',mktime(0,0,0,$month, 1, $year)) == 28)
    {
		$tStr = 'B'.$row.':AF'.$row.'';
    }
    if (date('t',mktime(0,0,0,$month, 1, $year)) == 29)
    {
        $tStr = 'B'.$row.':AG'.$row.'';
    }
    if (date('t',mktime(0,0,0,$month, 1, $year)) == 30)
    {
        $tStr = 'B'.$row.':AH'.$row.'';	
    }
    if (date('t',mktime(0,0,0,$month, 1, $year)) == 31)
    {
        $tStr = 'B'.$row.':AI'.$row.'';	
    }	
	
	
	
    $objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(1, $row, "Total");
	$objPHPExcel->getActiveSheet()->getStyle('B'.$row.'')->getFont()->setBold(true);
    $objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(3, $row, $total);
	$objPHPExcel->getActiveSheet()->getStyle('D'.$row.'')->getFont()->setBold(true);
	$objPHPExcel->getActiveSheet()->getStyle($tStr)->applyFromArray( 
            array( 'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'F7F2B2') )));
			
	$row = $row + 2;
	// Soit un total de:
	if (date('t',mktime(0,0,0,$month, 1, $year)) == 28)
    {
		$stStr = 'B'.$row.':AF'.$row.'';
    }
    if (date('t',mktime(0,0,0,$month, 1, $year)) == 29)
    {
        $stStr = 'B'.$row.':AG'.$row.'';
    }
    if (date('t',mktime(0,0,0,$month, 1, $year)) == 30)
    {
        $stStr = 'B'.$row.':AH'.$row.'';	
    }
    if (date('t',mktime(0,0,0,$month, 1, $year)) == 31)
    {
        $stStr = 'B'.$row.':AI'.$row.'';
	
	}
	
	$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(1, $row, "Soit un total de ");
	$objPHPExcel->getActiveSheet()->getStyle('B'.$row.'')->getFont()->setBold(true);
    $objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(3, $row, 'XXXX');
	$objPHPExcel->getActiveSheet()->getStyle('D'.$row.'')->getFont()->setBold(true);
	$objPHPExcel->getActiveSheet()->getStyle($stStr)->applyFromArray( 
            array( 'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'F7F2B2') )));
	
}
	
	
// Company / user name/ date:
$objPHPExcel->getActiveSheet()->getStyle("C2")->applyFromArray(array(
    'borders'=>array(
        'top'=>array(
            'style'=>PHPExcel_Style_Border::BORDER_MEDIUM),
        'left'=>array(
            'style'=>PHPExcel_Style_Border::BORDER_MEDIUM),
		'right'=>array(
            'style'=>PHPExcel_Style_Border::BORDER_MEDIUM),	
			)));		
$objPHPExcel->getActiveSheet()->getStyle("C2:C5")->applyFromArray(array(
    'borders'=>array(
        'left'=>array(
            'style'=>PHPExcel_Style_Border::BORDER_MEDIUM),
		'right'=>array(
            'style'=>PHPExcel_Style_Border::BORDER_MEDIUM),	
			)));		
$objPHPExcel->getActiveSheet()->getStyle("C5")->applyFromArray(array(
    'borders'=>array(
        'bottom'=>array(
            'style'=>PHPExcel_Style_Border::BORDER_MEDIUM),
        )));
		
//Column Dimension:
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(40);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('S')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('T')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('U')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('V')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('W')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('X')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('Y')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('Z')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('AA')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('AB')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('AC')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('AD')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('AE')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('AF')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('AG')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('AH')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('AI')->setWidth(5);
                                                                   


// Set fonts
if (date('t',mktime(0,0,0,$month, 1, $year)) == 28)
{
    $myStr = 'B8:AF8';	
}
if (date('t',mktime(0,0,0,$month, 1, $year)) == 29)
{
    $myStr = 'B8:AG8';	
}
if (date('t',mktime(0,0,0,$month, 1, $year)) == 30)
{
    $myStr = 'B8:AH8';	
}
if (date('t',mktime(0,0,0,$month, 1, $year)) == 31)
{
    $myStr = 'B8:AI8';	
}	


$objPHPExcel->getActiveSheet()->getStyle($myStr)->getFont()->setSize(12);
$objPHPExcel->getActiveSheet()->getStyle($myStr)->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle($myStr)->getBorders()->applyFromArray(
    		array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array( 'rgb' => '2B5714' ))));
$objPHPExcel->getActiveSheet()->getStyle($myStr)->applyFromArray( 
            array( 'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'BCCF00') )));
					
			
			

// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Monthly report');


// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="Monthly_Report.xls"');
header('Cache-Control: max-age=0');

//$data = new Spreadsheet_Excel_Reader("WeeklyReport.xls",true,"UTF-16");

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;


	/*		
if ($num == 0) {
    // Add some data
    $objPHPExcel->setActiveSheetIndex(0)
                ->setCellValue('B11', 'No data !');
	$objPHPExcel->getActiveSheet()->getStyle('B11')->applyFromArray( 
            array( 'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'FF0B0B') )));
    
	$objPHPExcel->getActiveSheet()->getStyle('C11')->applyFromArray( 
            array( 'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'FF0B0B') )));
	$objPHPExcel->getActiveSheet()->getStyle('D11')->applyFromArray( 
            array( 'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'FF0B0B') )));
    $objPHPExcel->getActiveSheet()->getStyle('E11')->applyFromArray( 
            array( 'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'FF0B0B') )));
	$objPHPExcel->getActiveSheet()->getStyle('F11')->applyFromArray( 
            array( 'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'FF0B0B') )));
    $objPHPExcel->getActiveSheet()->getStyle('G11')->applyFromArray( 
            array( 'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'FF0B0B') )));
	$objPHPExcel->getActiveSheet()->getStyle('H11')->applyFromArray( 
            array( 'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'FF0B0B') )));
    $objPHPExcel->getActiveSheet()->getStyle('I11')->applyFromArray( 
            array( 'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'FF0B0B') )));
} else {
    $row       = 11;
	$totalWeek = 0;
	
	while ($data = dbResult($qh)) 
	{
		$current_project_title = utf8_encode(stripslashes($data["projectTitle"]));
		$current_task_name     = utf8_encode(stripslashes($data["taskName"]));
		$identifier            = utf8_encode(stripslashes($data["identifier"]));
		$start_time            = $data["day_of_month"];
		$diff_sec              = $data["diff_sec"] / 60 / 60 / 8;
		$colum                 = 3 + ($data["day_of_month"] - $day ) ;
		$totalDay              = $diff_sec;
		$totalWeek             = $totalWeek + $diff_sec; 
		$exist                 = 0;
		$i                     = 11;

		for ($i == 11; $i<=$row; $i++)
		{
		    if( $identifier == $objPHPExcel->getActiveSheet()->getCell('C'.$i.'')->getValue()) 
		    {
			    $curentRow = $row;
				$row       = $i;
				$exist     = 1;
				//$value     = intval(objPHPExcel->getActiveSheet()->getCell('I'.$i.'')->getValue());
				//$totalDay  = $totalDay + $value;
			    break;
			
			} else {
			    // Add some data
    	        $objPHPExcel->setActiveSheetIndex(0)
		        			->setCellValueByColumnAndRow(1, $row,'' .$current_project_title. ' - ' .$current_task_name. '');
    		    $objPHPExcel->setActiveSheetIndex(0) 
                            ->setCellValueByColumnAndRow(2, $row, $identifier);	
			    break;
			
			
			}
		}
	    	
        //$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($colum, $row, $diff_sec);	
        $from = 'D'.$row.':H'.$row.'';		
		//$bob = =SUM('$from');
        //$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(8, $row, '=SUM(D$row:H$row)');
		
		$str = 'B'.$row.'';
		$objPHPExcel->getActiveSheet()->getStyle($str)->getFont()->setSize(11);
        $objPHPExcel->getActiveSheet()->getStyle($str)->getBorders()->applyFromArray(
    	    	array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array( 'rgb' => '2B5714' ))));
		$str = 'C'.$row.'';
		$objPHPExcel->getActiveSheet()->getStyle($str)->getFont()->setSize(11);
        $objPHPExcel->getActiveSheet()->getStyle($str)->getBorders()->applyFromArray(
    	    	array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array( 'rgb' => '2B5714' ))));			
		$str = 'D'.$row.'';
		$objPHPExcel->getActiveSheet()->getStyle($str)->getFont()->setSize(11);
        $objPHPExcel->getActiveSheet()->getStyle($str)->getBorders()->applyFromArray(
    	    	array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array( 'rgb' => '2B5714' ))));
		$str = 'E'.$row.'';
		$objPHPExcel->getActiveSheet()->getStyle($str)->getFont()->setSize(11);
        $objPHPExcel->getActiveSheet()->getStyle($str)->getBorders()->applyFromArray(
    	    	array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array( 'rgb' => '2B5714' ))));					
		$str = 'F'.$row.'';
		$objPHPExcel->getActiveSheet()->getStyle($str)->getFont()->setSize(11);
        $objPHPExcel->getActiveSheet()->getStyle($str)->getBorders()->applyFromArray(
    	    	array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array( 'rgb' => '2B5714' ))));
		$str = 'G'.$row.'';
		$objPHPExcel->getActiveSheet()->getStyle($str)->getFont()->setSize(11);
        $objPHPExcel->getActiveSheet()->getStyle($str)->getBorders()->applyFromArray(
    	    	array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array( 'rgb' => '2B5714' ))));			
		$str = 'H'.$row.'';
		$objPHPExcel->getActiveSheet()->getStyle($str)->getFont()->setSize(11);
        $objPHPExcel->getActiveSheet()->getStyle($str)->getBorders()->applyFromArray(
    	    	array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array( 'rgb' => '2B5714' ))));
		$str = 'I'.$row.'';
		$objPHPExcel->getActiveSheet()->getStyle($str)->getFont()->setSize(11);
        $objPHPExcel->getActiveSheet()->getStyle($str)->getBorders()->applyFromArray(
    	    	array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array( 'rgb' => '2B5714' ))));					
					
		if ($exist == 0)
        {		
		    $row ++;
        } else {
		    $row = $curentRow;
		}
		$exist = 0;
	}

				
	$objPHPExcel->setActiveSheetIndex(0)
			    ->setCellValueByColumnAndRow(1, $row,'Total');
	$objPHPExcel->setActiveSheetIndex(0)
			    ->setCellValueByColumnAndRow(8, $row, '' .$totalWeek. ' days');
				
	$str = 'B'.$row.'';
	$strToMerge = 'B'.$row.':H'.$row.'';
    $objPHPExcel->getActiveSheet()->mergeCells($strToMerge);
    $objPHPExcel->getActiveSheet()->getStyle($strToMerge)->getBorders()->applyFromArray(
    		array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array( 'rgb' => '2B5714' ))));
	$objPHPExcel->getActiveSheet()->getStyle($strToMerge)->getFont()->setSize(12);
    $objPHPExcel->getActiveSheet()->getStyle($str)->getFont()->setBold(true);
    $objPHPExcel->getActiveSheet()->getStyle($str)->applyFromArray( 
            array( 'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'BCCF00') )));
	
	// Total
	$str = 'I'.$row.'';
    $objPHPExcel->getActiveSheet()->getStyle($str)->getBorders()->applyFromArray(
    		array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array( 'rgb' => '2B5714' ))));
	$objPHPExcel->getActiveSheet()->getStyle($str)->getFont()->setSize(12);
	$objPHPExcel->getActiveSheet()->getStyle($str)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
				
				
				
				
				
}

// Signature:
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('B30', 'Signature :');			
$objPHPExcel->getActiveSheet()->getStyle('B30')->getFont()->setSize(12);

// Validation:
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('E30', 'Validation :');			
$objPHPExcel->getActiveSheet()->getStyle('E30')->getFont()->setSize(12);
*/



?>
